package com.arcvideo.acsplayer.utils;

import java.security.MessageDigest;

public class MD5Utils {

	public static String encode(byte[] bytes) {
		StringBuffer hexString = new StringBuffer();
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(bytes);
			byte[] digest = md.digest();
			String text;
			for (int i = 0; i < digest.length; i++) {
				text = Integer.toHexString(0xFF & digest[i]);
				if (text.length() < 2) {
					text = "0" + text;
				}
				hexString.append(text);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return hexString.toString();
	}

	public static String encode(String text) {
		return encode(text.getBytes());
	}
}
